package com.yuhang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuhang.entity.HyCar;
import com.yuhang.entity.HyPet;
import com.yuhang.entity.HyUser;
import com.yuhang.entity.StateMonth;
import com.yuhang.mapper.HyCarMapper;
import com.yuhang.mapper.HyPetMapper;
import com.yuhang.mapper.HyUserMapper;
import com.yuhang.service.HyCarService;
import com.yuhang.service.HyUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javafx.geometry.HPos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuhang
 * @since 2021-04-05
 */
@Service
public class HyUserServiceImpl extends ServiceImpl<HyUserMapper, HyUser> implements HyUserService {

    @Autowired
    private HyUserMapper hyUserMapper;
    @Autowired
    private HyCarMapper hyCarMapper;
    @Autowired
    private HyPetMapper hyPetMapper;

    @Override
    public List<HyUser> selectUserPage(int pageNum, int pageSize, String likename, String liketelephone, Integer buildId) {
        int first = pageSize*(pageNum-1);
        List<HyUser> hyUserIPage = hyUserMapper.selectPage(first,pageSize,likename,liketelephone,buildId);
        return hyUserIPage;
    }

    @Override
    public List<StateMonth> selectOrderByBuild() {
        return hyUserMapper.selectOrderByBuild();
    }

    @Override
    public void deleteCarAndPetByUserId(int id) {
        QueryWrapper<HyCar> carQueryWrapper = new QueryWrapper();
        carQueryWrapper.eq("user_id",id);
        hyCarMapper.delete(carQueryWrapper);
        QueryWrapper<HyPet> petQueryWrapper = new QueryWrapper();
        petQueryWrapper.eq("user_id",id);
        hyPetMapper.delete(petQueryWrapper);
    }

}
